<?php
require_once("../core/core.inc");

// TODO: recognize it
$backend = true;

$p = Utils::params();

switch(Utils::get("cmd", false)) {
	case "login":
		$usr = Users::get($p["usr"], $p["pw"]);
		if($usr!==false){
			echo $usr;
		} else {
			echo "null";
		}
		break;
	case "username":
		$usr = DB::load($p["usr"]);
		if($usr!==false) {
			echo $usr->name;
		}
	case "usergame":
		$usr = DB::load($p["usr"]);
		$gameId = $usr->game;
		$gm = DB::load($gameId);
		if($usr!==false) {
			echo $gm->json();
		}
	case false:
		return;
		break;
}

//$s = Server::_();
//$s->addGames(2, "TicTacToe");
//DB::save($s);
//print_r($s);

//$games = $s->gameList();
//echo "<pre>";
//print_r($games);

//$s->addGames(2, "TicTacToe");

?>